<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>伸缩式搜索框</title>
  <style>
    /* 搜索框容器样式 */
    .search-box {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      background-color: #2f3640;
      height: 40px;
      padding: 40px;
      border-radius: 40px;
    }
    /* 搜索输入框样式 */
    .search-txt {
      border: none;
      background: none;
      outline: none;
      float: left;
      padding: 0;
      color: #fff;
      font-size: 16px;
      line-height: 40px;
      width: 0;
      transition: width 0.4s; /* 添加过渡效果 */
    }
    /* 搜索按钮样式 */
    .search-btn {
      color: #e84118;
      float: right;
      width: 40px;
      height: 40px;
      border-radius: 50%;
      background-color: #2f3640;
      display: flex;
      justify-content: center;
      align-items: center;
      cursor: pointer;
      transition: background-color 0.4s; /* 添加过渡效果 */
    }
    /* 悬停时搜索输入框和按钮的样式 */
    .search-box:hover .search-txt {
      width: 200px;
      padding: 0 6px;
    }
    .search-box:hover .search-btn {
      background-color: #fff;
    }
  </style>
</head>
<body>
  <div class="search-box">
    <input type="text" class="search-txt" placeholder="请输入搜索内容">
    <a class="search-btn">
      <i class="fa fa-search" aria-hidden="true"></i>
    </a>
  </div>
</body>
</html>